-
Notifications
You must be signed in to change notification settings - Fork 28
Interval formatters #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
reason is that we need to use it in tests where values need to implement Eq and Show
bower.json
Outdated
"purescript-fixed-points": "^4.0.0", | ||
"purescript-datetime": "^3.0.0" | ||
"purescript-datetime": "git://github.com/safareli/purescript-datetime.git#interval", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛑 should be changed after purescript/purescript-datetime#52 is merged
@cryogenian can you take another look. |
@cryogenian can you take another look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two small picky things feel free to merge with or without them :)
src/Data/Formatter/DateTime.purs
Outdated
|
||
exactLength ∷ ∀ e. ReaderT { maxLength ∷ Int, length ∷ Int | e } (Either String) Unit | ||
exactLength = ask >>= \({maxLength, length}) → if maxLength /= length | ||
then lift $ Left $ "Expected " <> (show maxLength) <> " digits but got " <> (show length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both branches have lift
you can put it before if
src/Data/Formatter/DateTime.purs
Outdated
|
||
validateRange ∷ ∀ e. Int → Int → ReaderT { num ∷ Int | e } (Either String) Unit | ||
validateRange min max = ask >>= \({num}) → if num < min || num > max | ||
then lift $ Left $ "Number is out of range [ " <> (show min) <> ", " <> (show max) <> " ]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same two lift
s
src/Data/Formatter/DateTime.purs
Outdated
-- | | ||
-- | The `Lazy` constraint is used to generate the result lazily, to ensure | ||
-- | termination. | ||
takeSome :: forall f a. Alternative f => Z.Lazy (f (List.List a)) => Int -> f a -> f (List.List a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent arrows and forall symbols here
src/Data/Formatter/DateTime.purs
Outdated
→ P.ParserT String m Int | ||
parseInt maxLength validators errMsg = do | ||
ds ← takeSome maxLength parseDigit | ||
let length = List.length ds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double let
src/Data/Formatter/DateTime.purs
Outdated
YearTwoDigits → _{year = _} `modifyWithParser` | ||
(parseInt 2 exactLength "Incorrect 2-digit year") | ||
YearAbsolute → _{year = _} `modifyWithParser` | ||
(pure (*) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lift2
?
src/Data/Formatter/DateTime.purs
Outdated
, minute: Just $ fromEnum $ T.minute t | ||
, second: Just $ fromEnum $ T.second t | ||
, millisecond: Just $ fromEnum $ T.millisecond t | ||
, meridiem: (Nothing ∷ Maybe Meridiem) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this annotation still needed?
parseIsoDuration = do | ||
dur ← parseDuration | ||
case mkIsoDuration dur of | ||
Left errs → let errorStr = intercalate ", " (prettyError <$> errs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda non-common formatting. Could you put let
on the next line?
notEmpty p str = p >>= \x → if x == mempty then P.fail str else pure x | ||
|
||
mkComponentsParser ∷ Array (Tuple (Number → I.Duration) String) → P.Parser String I.Duration | ||
mkComponentsParser arr = p `notEmpty` ("None of valid duration components (" <> (show $ snd <$> arr) <> ") were present") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest using operator instead of infix function here. Like <?>
in strongcheck. Or prefix func application. It's a bit mistyfying in that case, I mean infix notEmpty
, maybe msgIfEmpty
or something else.
Compare:
p <:?:> "Critical Error!!!"
nonEmptyParser p "Critical Error!!!"
p `messageIfInputIsEmpty` "Critical Error!!!"
Depends on purescript/purescript-datetime#52